import { createApp } from "vue";
import GlobalDialog from "@/components/GlobalDialog.vue";

let instance = null;

export const dialog = {
  show(options = {}) {
    if (!instance) {
      const div = document.createElement("div");
      document.body.appendChild(div);
      instance = createApp(GlobalDialog).mount(div);
    }
    instance.open(options);
  },
  hide() {
    if (instance) {
      instance.close();
    }
  },
};

export default {
  install(app) {
    app.config.globalProperties.$dialog = dialog;
  },
};
